<%-- 
    Document   : inc_teacher_form
    Created on : Jan 10, 2013, 12:25:26 PM
    Author     : matt
--%>

<%@page import="com.gestionabsences.form.FormTeacher"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>

<table class="tab_form">
    <tr>
	<th><label for="<% out.print(FormTeacher.CHAMP_MATIERE);%>">matière</label></th>
	<th><label for="<% out.print(FormTeacher.CHAMP_NBRE_ABSENCES);%>">opérateur</label></th>
	<th class="nbrAbsences"><label for="<% out.print(FormTeacher.CHAMP_OPTION_NBRE_ABSENCES);%>">nombre d'absences</label></th>
	<th class="justification"><label for="<% out.print(FormTeacher.CHAMP_OPTION);%>">option justifications</label></th>
    </tr>
    <tr>
	<td>
	    <select class="matiere" name="<% out.print(FormTeacher.CHAMP_MATIERE);%>" id="<% out.print(FormTeacher.CHAMP_MATIERE);%>">
		<option value="ALL" selected>Toutes</option>
		<option value="IN_ONE">Une d'elles</option>
		<c:forEach items="${ sessionScope.listeMatieres }" var="mapMatieres" varStatus="boucle">
		    <option value="${ mapMatieres.key }">${ mapMatieres.value }</option>
		</c:forEach>
	    </select>
	</td>
	<td>
	    <select class="operateur" name="<% out.print(FormTeacher.CHAMP_OPTION_NBRE_ABSENCES);%>" onclick="displayResult()" id="<% out.print(FormTeacher.CHAMP_OPTION_NBRE_ABSENCES);%>">
		<option value="WITHOUT">Sans opérateur</option>
		<option class="notCompatibleALL" value=">">></option>
		<option class="notCompatibleALL" value="<"><</option>
		<option class="notCompatibleALL" value="=">=</option>
		<option class="notCompatibleALL" value=">=">>=</option>
		<option class="notCompatibleALL" value="<="><=</option>
		<option class="notCompatibleIN_ONE" value="NEVER">jamais absent</option>
		<option class="notCompatibleIN_ONE" value="ALWAYS">toujours absent</option>
	    </select>
	</td>
	<td class="nbrAbsences">
	    <input type="number" name="<% out.print(FormTeacher.CHAMP_NBRE_ABSENCES);%>" id="<% out.print(FormTeacher.CHAMP_NBRE_ABSENCES);%>" min="0" step="1" style="text-align:center;" />
	</td>
	<td>
	    <select class="justification" name="<% out.print(FormTeacher.CHAMP_OPTION);%>" id="<% out.print(FormTeacher.CHAMP_OPTION);%>">
		<option value="ALL" selected>Toutes</option>
		<option value="withJustifications">Avec justification</option>
		<option value="withoutJustifications">Sans justification</option>
	    </select>
	</td>
    </tr>
    <!--<tr id="printarea"></tr>-->
</table>

<c:if test="${ !empty form.erreurs['matiere'] }">
    <p class="help-inline">${form.erreurs['matiere']}</p>
</c:if>
<c:if test="${ !empty form.erreurs['optionNbrAbsences'] }">
    <p class="help-inline">${form.erreurs['optionNbrAbsences']}</p>
</c:if>
<c:if test="${ !empty form.erreurs['nbrAbsences'] }">
    <p class="help-inline">${form.erreurs['nbrAbsences']}</p>
</c:if>
<c:if test="${ !empty form.erreurs['option'] }">
    <p class="help-inline">${form.erreurs['option']}</p>
</c:if>
<c:if test="${ !empty form.erreurs['erreur'] }">	
    <p class="help-inline">${form.erreurs['erreur']}</p>
</c:if>

<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
    $('.operateur').change(function () {
	//var str = "";
	
	var selectedOption = $('.operateur option:selected').val();
	if(selectedOption == "WITHOUT" || selectedOption == "NEVER" || selectedOption == "ALWAYS") {
	    //str = "on supprime les nombres";
	    $('.nbrAbsences').css('display', 'none');
	    if(selectedOption == "NEVER") {
		$('.justification').css('display', 'none');
	    } else if(selectedOption == "ALWAYS") {
		$('.justification').css('display', 'block');
	    }
	} else {
	    $('.nbrAbsences').css('display', 'block');
	    $('.justification').css('display', 'block');
	    //str = "on affiche les nombres";
	}
	
	//$('#printarea').text(str);
    })
    .change();
    
    $('.matiere').change(function () {
	var str = "";
	
	var selectedOption = $('.matiere option:selected').val();
	if(selectedOption == "ALL") {
	    $('.notCompatibleALL').css('display', 'none');
	    $('.notCompatibleIN_ONE').css('display', 'block');
	} else if(selectedOption == "IN_ONE") {
	    $('.notCompatibleIN_ONE').css('display', 'none');
	    $('.notCompatibleALL').css('display', 'block');
	} else {
	    $('.notCompatibleALL').css('display', 'block');
	    $('.notCompatibleIN_ONE').css('display', 'block');
	}
    })
    .change();
</script>